package com.xinchao.ck_mips.impl;

import com.xinchao.ck_mips.bean.ConfigBean;
import com.xinchao.ck_mips.bean.DeviceInfoBean;
import com.xinchao.ck_mips.bean.NewestProgramBean;
import com.xinchao.ck_mips.bean.UpgradeBean;
import com.xinchao.ck_mips.http.CKRequestSubscriber;
import com.xinchao.ck_mips.model.IPlayModel;

import java.util.List;

/**
 * Created by wq on 2019/5/7.
 */
public class PlayModelImpl implements IPlayModel {

    @Override
    public void report(int hours, String ip, long rebootTime, IReportCallbackListener mListener) {
        requestIoThread(getService().report(hours, ip, rebootTime),
                new CKRequestSubscriber<DeviceInfoBean>() {
                    @Override
                    protected void onRequestSuccess(DeviceInfoBean bean) {
                        mListener.success(bean);
                    }

                    @Override
                    protected void onRequestError(Throwable t) {
                        super.onRequestError(t);
                        mListener.error(t);
                    }
                });
    }

    @Override
    public void getNewestSetting(ISettingCallbackListener mListener) {
        requestIoThread(getService().getNewestSetting(), new CKRequestSubscriber<ConfigBean>() {
            @Override
            protected void onRequestSuccess(ConfigBean configBean) {
                mListener.success(configBean);
            }

            @Override
            protected void onRequestError(Throwable t) {
                super.onRequestError(t);
                mListener.error(t);
            }
        });
    }

    @Override
    public void getUpgrade(IUpgradeCallbackListener mListener) {
        requestIoThread(getService().getUpgrade(), new CKRequestSubscriber<List<UpgradeBean>>() {
            @Override
            protected void onRequestSuccess(List<UpgradeBean> upgradeBeans) {
                mListener.success(upgradeBeans);
            }

            @Override
            protected void onRequestError(Throwable t) {
                super.onRequestError(t);
                mListener.error(t);
            }
        });
    }

    @Override
    public void getNewestSettingReply(String number, INewestSettingReplyCallbackListener mListener) {
        requestIoThread(getService().getNewestSettingReply(number), new CKRequestSubscriber<Object>() {
            @Override
            protected void onRequestSuccess(Object o) {
                mListener.success();
            }

            @Override
            protected void onRequestError(Throwable t) {
                super.onRequestError(t);
                mListener.error(t);
            }
        });
    }

    @Override
    public void getUpgradeReply(String number, IUpgradeReplyCallbackListener mListener) {
        requestIoThread(getService().getUpgradeReply(number), new CKRequestSubscriber<String>() {
            @Override
            protected void onRequestSuccess(String s) {
                mListener.success();
            }

            @Override
            protected void onRequestError(Throwable t) {
                super.onRequestError(t);
                mListener.error(t);
            }
        });
    }

    @Override
    public void settingSync(int volume, ISettingSyncCallbackListener mListener) {
        requestIoThread(getService().settingSync(volume), new CKRequestSubscriber<Object>() {
            @Override
            protected void onRequestSuccess(Object o) {
                mListener.success();
            }

            @Override
            protected void onRequestError(Throwable t) {
                super.onRequestError(t);
                mListener.error(t);
            }
        });
    }

    @Override
    public void getNewestProgram(long capacity, IProgramCallbackListener mListener) {
        requestIoThread(getService().getNewestProgram(capacity), new CKRequestSubscriber<NewestProgramBean>() {
            @Override
            protected void onRequestSuccess(NewestProgramBean newestProgramBean) {
                mListener.success(newestProgramBean);
            }

            @Override
            protected void onRequestError(Throwable t) {
                super.onRequestError(t);
                mListener.error(t);
            }
        });
    }

    @Override
    public void getNewestProgramReply(String serialNo, IProgramReplyCallbackListener mListener) {
        requestIoThread(getService().getNewestProgramReply(serialNo), new CKRequestSubscriber<Object>() {
            @Override
            protected void onRequestSuccess(Object o) {
                mListener.success();
            }

            @Override
            protected void onRequestError(Throwable t) {
                super.onRequestError(t);
                mListener.error(t);
            }
        });
    }

    @Override
    public void uploadWifiMAC(long uploadTime, String url, IUploadWifiMacCallbackListener mListener) {
        request(getService().uploadWifiMAC(uploadTime, url), new CKRequestSubscriber<Object>() {
            @Override
            protected void onRequestSuccess(Object o) {
                mListener.success();
            }

            @Override
            protected void onRequestError(Throwable t) {
                super.onRequestError(t);
                mListener.error(t);
            }
        });
    }

    @Override
    public void uploadProgramStatus(int state, String version, String reason, IUploadProgramStatusCallbackListener mListener) {
        requestIoThread(getService().uploadDownloadStatus(state, version, reason), new CKRequestSubscriber<Object>() {
            @Override
            protected void onRequestSuccess(Object o) {
                mListener.success();
            }

            @Override
            protected void onRequestError(Throwable t) {
                super.onRequestError(t);
                mListener.error(t);
            }
        });
    }

    @Override
    public void uploadLog(String type, String url, IUploadLogCallbackListener mListener) {
        request(getService().uploadLog(type, url), new CKRequestSubscriber<Object>() {
            @Override
            protected void onRequestSuccess(Object o) {
                mListener.success();
            }

            @Override
            protected void onRequestError(Throwable t) {
                super.onRequestError(t);
                mListener.error(t);
            }
        });
    }

    @Override
    public void reportShow(String jsonData, String offLineTime, IReportShowCallbackListener mListener) {
        requestIoThread(getService().reportShow(jsonData), new CKRequestSubscriber<Object>() {
            @Override
            protected void onRequestSuccess(Object o) {
                mListener.success(offLineTime);
            }

            @Override
            protected void onRequestError(Throwable t) {
                super.onRequestError(t);
                mListener.error(t);
            }
        });
    }

}
